package sge.data;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import sge.beans.Ementa;

public class EmentaDAO {

	private static EmentaDAO dao;

	private EmentaDAO() {
	}

	public static EmentaDAO obterEmentaDAO() {
		if (dao == null) {
			dao = new EmentaDAO();
		}
		return dao;
	}

	public void inserirEmenta(Ementa ementa) {
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			pm.makePersistent(ementa);
		} finally {
			pm.close();
		}
	}

	@SuppressWarnings("unchecked")
	public List<Ementa> todosEmentas() {
		List<Ementa> lista = new ArrayList<Ementa>();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			Query query = pm.newQuery(Ementa.class);
			lista.addAll((List<Ementa>) query.execute());
		} finally {
			pm.close();
		}
		return lista;
	}
}
